/**
   uni.request()封装
   @prams{*} 请求参数
 */
// 设置基准地址
const BASE_URL = "https://api-ugo-dev.itheima.net/api/public/v1"
export default async function myRequest ({ url, method, data, header}) {
  uni.showLoading({
    title:'加载中...',
    mask:true
  });
  let [err,res] = await uni.request({
    url:BASE_URL + url,
    method,
    header,
    data
  })
  uni.hideLoading();
  if (!err) {
    const {data:{message,meta}} = res
    return {
      msg:meta,
      data:message
    }
  } else {
    return err
  }
}

//vue的插件
const MyPlug = {
  //vue参数
  install (Vue) {
    Vue.prototype.request = myRequest
  }
}
export {MyPlug}